listbase: Move a common function from the children into GtkListBase
authorBenjamin Otte <otte@redhat.com>
Wed, 24 Jun 2020 02:49:21 +0000 (04:49 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 26 Jun 2020 05:13:32 +0000 (07:13 +0200)
We want to use it for the rubberband later.

gtk/gtkgridview.c
gtk/gtklistbase.c
gtk/gtklistbaseprivate.h
gtk/gtklistview.c

index 5b2a381c6902b0ece63ce745930debbd45ea99b3..5fde3eb8957402d3e75d96008fc6462002ee0bc1 100644 (file)
@@ -687,43 +687,6 @@ cell_set_size (Cell  *cell,
   gtk_rb_tree_node_mark_dirty (cell);
 }
 
-static void
-gtk_grid_view_size_allocate_child (GtkGridView *self,
-                                   GtkWidget   *child,
-                                   int          x,
-                                   int          y,
-                                   int          width,
-                                   int          height)
-{
-  GtkAllocation child_allocation;
-
-  if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == GTK_ORIENTATION_VERTICAL)
-    {
-      child_allocation.x = x;
-      child_allocation.y = y;
-      child_allocation.width = width;
-      child_allocation.height = height;
-    }
-  else if (_gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR)
-    {
-      child_allocation.x = y;
-      child_allocation.y = x;
-      child_allocation.width = height;
-      child_allocation.height = width;
-    }
-  else
-    {
-      int mirror_point = gtk_widget_get_width (GTK_WIDGET (self));
-
-      child_allocation.x = mirror_point - y - height; 
-      child_allocation.y = x;
-      child_allocation.width = height;
-      child_allocation.height = width;
-    }
-
-  gtk_widget_size_allocate (child, &child_allocation, -1);
-}
-
 static int
 gtk_grid_view_compute_total_height (GtkGridView *self)
 {
@@ -873,7 +836,7 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
         {
           row_height += cell->size;
 
-          gtk_grid_view_size_allocate_child (self,
+          gtk_list_base_size_allocate_child (GTK_LIST_BASE (self),
                                              cell->parent.widget,
                                              x + ceil (self->column_width * i),
                                              y,
index c18db8a5dc29804ca195bc1eae56f3df91556a18..70036eedf3e79a3ee953ac2be700253f2e2e44d4 100644 (file)
@@ -1337,6 +1337,56 @@ update_autoscroll (GtkListBase *self,
     remove_autoscroll (self);
 }
 
+/**
+ * gtk_list_base_size_allocate_child:
+ * @self: The listbase
+ * @child: 
+ * @x: top left coordinate in the across direction
+ * @y: top right coordinate in the along direction
+ * @width: size in the across direction
+ * @height: size in the along direction
+ *
+ * Allocates a child widget in the list coordinate system,
+ * but with the coordinates already offset by the scroll
+ * offset.
+ **/
+void
+gtk_list_base_size_allocate_child (GtkListBase *self,
+                                   GtkWidget   *child,
+                                   int          x,
+                                   int          y,
+                                   int          width,
+                                   int          height)
+{
+  GtkAllocation child_allocation;
+
+  if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == GTK_ORIENTATION_VERTICAL)
+    {
+      child_allocation.x = x;
+      child_allocation.y = y;
+      child_allocation.width = width;
+      child_allocation.height = height;
+    }
+  else if (_gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR)
+    {
+      child_allocation.x = y;
+      child_allocation.y = x;
+      child_allocation.width = height;
+      child_allocation.height = width;
+    }
+  else
+    {
+      int mirror_point = gtk_widget_get_width (GTK_WIDGET (self));
+
+      child_allocation.x = mirror_point - y - height; 
+      child_allocation.y = x;
+      child_allocation.width = height;
+      child_allocation.height = width;
+    }
+
+  gtk_widget_size_allocate (child, &child_allocation, -1);
+}
+
 void
 gtk_list_base_allocate_rubberband (GtkListBase *self)
 {
index 7cf0504a439c1b8d55a34707ad9448a01fa62ea0..87df14d2d2ff015d34a03419b837a4843c7b6a7e 100644 (file)
@@ -99,10 +99,17 @@ gboolean               gtk_list_base_grab_focus_on_item         (GtkListBase
                                                                  gboolean                select,
                                                                  gboolean                modify,
                                                                  gboolean                extend);
+
 void                   gtk_list_base_set_enable_rubberband      (GtkListBase            *self,
                                                                  gboolean                enable);
 gboolean               gtk_list_base_get_enable_rubberband      (GtkListBase            *self);
-
 void                   gtk_list_base_allocate_rubberband        (GtkListBase            *self);
 
+void                   gtk_list_base_size_allocate_child        (GtkListBase            *self,
+                                                                 GtkWidget              *child,
+                                                                 int                     x,
+                                                                 int                     y,
+                                                                 int                     width,
+                                                                 int                     height);
+
 #endif /* __GTK_LIST_BASE_PRIVATE_H__ */
index 484f5b172c4202d100e4330c15558e00ca78ae44..b34b216e7193a52f7219e86baa4f4dc22e413a2d 100644 (file)
@@ -553,43 +553,6 @@ gtk_list_view_measure (GtkWidget      *widget,
     gtk_list_view_measure_across (widget, orientation, for_size, minimum, natural);
 }
 
-static void
-gtk_list_view_size_allocate_child (GtkListView *self,
-                                   GtkWidget   *child,
-                                   int          x,
-                                   int          y,
-                                   int          width,
-                                   int          height)
-{
-  GtkAllocation child_allocation;
-
-  if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == GTK_ORIENTATION_VERTICAL)
-    {
-      child_allocation.x = x;
-      child_allocation.y = y;
-      child_allocation.width = width;
-      child_allocation.height = height;
-    }
-  else if (_gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR)
-    {
-      child_allocation.x = y;
-      child_allocation.y = x;
-      child_allocation.width = height;
-      child_allocation.height = width;
-    }
-  else
-    {
-      int mirror_point = gtk_widget_get_width (GTK_WIDGET (self));
-
-      child_allocation.x = mirror_point - y - height; 
-      child_allocation.y = x;
-      child_allocation.width = height;
-      child_allocation.height = width;
-    }
-
-  gtk_widget_size_allocate (child, &child_allocation, -1);
-}
-
 static void
 gtk_list_view_size_allocate (GtkWidget *widget,
                              int        width,
@@ -685,7 +648,7 @@ gtk_list_view_size_allocate (GtkWidget *widget,
     {
       if (row->parent.widget)
         {
-          gtk_list_view_size_allocate_child (self,
+          gtk_list_base_size_allocate_child (GTK_LIST_BASE (self),
                                              row->parent.widget,
                                              x,
                                              y,